<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php 
	if( !isset($_COOKIE["username"]) ){
		echo "<script>window.location.href='login.php'</script>";
	}else{
		setcookie("username", $_COOKIE["username"],time() + 900);
	}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Patient Report</title>
<link href="css/template.css" rel="stylesheet" type="text/css" />
<script src="js/droplinemenu.js" type="text/javascript"></script>
<script src="js/OperateTool.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
//build menu with DIV ID="myslidemenu" on page:
droplinemenu.buildmenu("nav")
</script>

<style type="text/css">
#	table{
#		border-collapse:collapse;
#	}
#	table td{
#		border:solid 1px blue;
#	}
</style>
t
<link href="css/ui-lightness/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<script src="js/jquery-1.8.3.js"></script>
<script src="js/jquery-ui-1.9.2.custom.js"></script>

<script>



	function printReport(){
		document.getElementById("header").style.display = "none";
		document.getElementById("headerTitle").style.display = "none";
		document.getElementById("nav").style.display = "none";
		document.getElementById("outLetter").style.display = "none";
		document.getElementById("footer").style.display = "none";
		//alert(document.getElementById("main_content").style.width);
		document.getElementById("container").style.width = "100%";
		//document.getElementById("headTableDiv").style.width = "85%";
		//document.getElementById("contentTableDiv").style.width = "85%";
		//document.getElementById("medicalTableDiv").style.width = "85%";
		
		window.print();
		document.getElementById("header").style.display = "block";
		document.getElementById("headerTitle").style.display = "block";
		document.getElementById("nav").style.display = "block";
		document.getElementById("outLetter").style.display = "block";
		document.getElementById("footer").style.display = "block";
		document.getElementById("container").style.width = "1200px";
		document.getElementById("headTableDiv").style.width = "1000px";
		document.getElementById("contentTableDiv").style.width = "1000px";
		document.getElementById("medicalTableDiv").style.width = "1000px";
		var appointmentNo = document.getElementById("appointmentNo").value;
		jQuery.ajax({type:'post', data:"appointmentNo=" + appointmentNo, url:'set_print_status.php', success:function(result){
				;
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){
				alert(XMLHttpRequest.responseText);
			}
		});
	}





	

	

	function previousPage(){
		var lastURL = document.referrer;
		if( lastURL.indexOf("review_patient.php") == -1 && lastURL.indexOf("list_unprint_report.php") == -1){
			SetCookie("appointmentPrevious", "");
			window.location.href = "review_patient.php?appointmentNo=" + document.getElementById("appointmentNo").value;
		}else{
			window.location.href = lastURL;
		}
		
	}
</script>
</head>

<body>
	<div id="container" style="width:1200px;" >
		<div id="header"></div>
		<?php include_once 'nav.php';?>
		<?php 
			if( !isset($_GET["appointmentNo"]) || preg_match("/^\d+$/", $_GET["appointmentNo"]) == false ){
				echo "<script>alert('No appointment no find!');window.location.href='index.php';</script>";
			}
			
			$ini_array = parse_ini_file("config/config.ini");
	
			$conn = @mysqli_connect($ini_array["host"], $ini_array["username"], $ini_array["password"], $ini_array["db_name"]) or die("cann't connect the mysql db");
			mysqli_set_charset($conn, "utf8");
			ini_set('default_charset', "UTF-8");
			date_default_timezone_set($ini_array["default_timezone"]);
			
			$appointmentNo = mysqli_real_escape_string($conn,$_GET["appointmentNo"]);
			$getInfoSql = "SELECT visit.`Patient_no`,visit.`Datetime_patient_seen`, visit.`signs`, visit.`symptoms`, visit.`diagnosis`, visit.`treatment`, visit.`comments`, 
			clinic.`Clinic_detail`, patient.`First_name`, patient.`Surname`, patient.`address`, patient.`Date_birth`,doctor.`Doctor_no`, doctor.`doctor_first_name`, doctor.`doctor_surname`, 
			doctor.`doctor_title`, doctor.`doctor_address`, doctor.`known_as`, appointment.isFirstVisit
			FROM visit LEFT OUTER JOIN patient ON visit.`Patient_no` = patient.`Patient_no` 
			LEFT OUTER JOIN clinic ON visit.`Clinic_no`=clinic.`Clinic_no` 
			LEFT OUTER JOIN doctor ON patient.doctor_no=doctor.`Doctor_no`, 
			appointment WHERE visit.Appointment_no = appointment.`appointment_no` AND  visit.`Appointment_no`= $appointmentNo";
			
			
	
			
			date_default_timezone_set($ini_array["default_timezone"]);
			
			$infoResult = mysqli_query($conn, $getInfoSql);
			
			
			$patientNo = 0;
			$datetimeSeen = "";
			$signs = "";
			$symtoms = "";
			$diagnosis = "";
			$treatment = "";
			$comments = "";
			$clinicDetail = "";
			$patientFirstName = "";
			$patientSurname = "";
			$patientAddress = "";
			$doctorNo = 0;
			$doctorFirstName = "";
			$doctorSurname = "";
			$doctorTitle = "";
			$doctorAddress = "";
			$isFirstVisit = 0;
			$patientBirth ="";
			$knownAs = "";
			
			if( $row = mysqli_fetch_array($infoResult) ){
				$patientNo = $row["Patient_no"];
				$datetimeSeen = date("d/m/Y", strtotime($row["Datetime_patient_seen"]));
				$signs = $row["signs"];
				$symtoms = $row["symptoms"];
				$diagnosis = $row["diagnosis"];
				$treatment = $row["treatment"];
				$comments = $row["comments"];
				$clinicDetail = $row["Clinic_detail"];
				$patientFirstName = $row["First_name"];
				$patientSurname = $row["Surname"];
				$patientAddress = $row["address"];
				$doctorNo = $row["Doctor_no"];
				$doctorFirstName = $row["doctor_first_name"];
				$doctorSurname = $row["doctor_surname"];
				$doctorTitle = $row["doctor_title"];
				$doctorAddress = $row["doctor_address"];
				$isFirstVisit = $row["isFirstVisit"];
				$patientBirth = date("d-m-Y", strtotime($row["Date_birth"]));
				$knownAs = $row["known_as"];
			}else{
				echo "<script>alert('this appointment no has no visit record!!!');window.location.href='index.php'</script>";
			}
			
		?>
		<div id="main_content">
			<div id="headTableDiv" style="margin:55px auto 20px;width:1000px;">
				<table id="headTable" style="border:1px;border-color:#a0c6e5;border-collapse:collapse;width:85%;margin:0px auto;">
					<tr>
						<td rowspan="2" style="text-align:center;background-color:#f4f4f4;border-top:solid 1px #e6e6e6;border-left:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6;"><label>Dr. Geraldine Morrow</label></td>
						<td colspan="2" style="border-right:solid 1px #e6e6e6;border-top:solid 1px #e6e6e6;"><label>Clinic Details: </label></td>
					</tr>
					<tr>
						<td></td>
						<td style="border-right:solid 1px #e6e6e6;"><label>•	Mount Carmel Hospital, Dublin 14</label></td>
					</tr>
					<tr>
						<td style="width:40%;text-align:center;background-color:#f4f4f4;border-left:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6;"><label>Consultant Dermatologist</label></td>
						<td style="width:10%"></td>
						<td style="width:50%;border-right:solid 1px #e6e6e6;"><label>•	Beacon Consultants Clinic, Sandyford, Dublin 18</label></td>
					</tr>
					<tr>
						<td style="text-align:center;background-color:#f4f4f4;border-left:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6;"><label>M.B., B.Ch., B.A.O., M.R.C.P.I.</label></td>
						<td></td>
						<td style="border-right:solid 1px #e6e6e6;">•	Vista Clinic, Naas, Co. Kildare. </td>
					</tr>
					<tr>
						<td style="height:12px;background-color:#f4f4f4;border-left:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6;"></td>
						<td style="border-right:solid 1px #e6e6e6;" colspan="2">&nbsp;&nbsp;&nbsp;HLC at DCU (Collins Avenue)</td>
					</tr>
					<tr>
						<td rowspan="2" style="text-align:center;background-color:#e6e6e6;border-left:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6;border-top:solid 1px #e6e6e6;">www.geraldinemorrow.com</td>
						<td style="height:12px;background-color:#e6e6e6;border-top:solid 1px #e6e6e6;"></td>
						<td style="background-color:#e6e6e6;border-top:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6;"></td>
	
					</tr>
					<tr>
						<td colspan="2" style="background-color:#e6e6e6;border-right:solid 1px #e6e6e6;"><label>All Correspondence to:       39 Grosvenor Road,  Rathmines,  D6</label></td>
	
					</tr>
					<tr>
						<td rowspan="2" style="text-align:center;background-color:#e6e6e6;border-left:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6;border-bottom:solid 1px #e6e6e6;">Medical Council  Reg. No. 09981</td>
						<td colspan="2" style="background-color:#e6e6e6;border-right:solid 1px #e6e6e6;"><label>Phone :   01-4970392          Fax.:  01-4974119</label></td>
	
					</tr>
					<tr>
						<td colspan="2" style="background-color:#e6e6e6;border-right:solid 1px #e6e6e6;border-bottom:solid 1px #e6e6e6;"><label>e-mail:     dermatology.secretary@gmail.com   </label></td>
	
					</tr>
				</table>
			</div>
			<div id="contentTableDiv" style="margin:40px auto 15px;width:1000px;">
				<table style="width:85%;border-collapse:collapse;margin:0px auto;" id="contentTable">
					<tr>
						<td style="text-align:right;width:60px;">To:</td>
						<td style="width:100px;"><?php echo $doctorTitle."  ".$doctorFirstName."  ".$doctorSurname ?></td>
						<td style="text-align:right;width:40px;">Re:</td>
						<td style="width:140px;"><?php echo $patientFirstName."  ".$patientSurname?></td>
						<td style="width:25px;"></td>
					</tr>
					<tr>
						<td style=""></td>
						<td><div style="margin:8px 0px;"><?php echo $doctorAddress?></div></td>
						<td></td>
						<td><div style="margin:8px 0px;"><?php echo $patientAddress?></div></td>
						<td></td>
					</tr>
					<tr>
						<td style="text-align:right;border-bottom:solid 1px black;height:30px;">Ref No.:</td>
						<td style="border-bottom:solid 1px black;"><?php echo $patientNo?></td>
						<td style="text-align:right;border-bottom:solid 1px black;">Date:</td>
						<td style="border-bottom:solid 1px black;"><?php echo date("d/m/Y")?></td>
						<td style=""></td>
					</tr>
					<tr>
						<td style="" colspan="4"><div style="margin:8px 0px 0px;">Dear <?php echo $knownAs?>:</div></td>
					</tr>
					<tr>
						<td style="border-bottom:solid 1px black;"></td>
						<td colspan="3" style="border-bottom:solid 1px black;"><div style="margin:8px 0px;">Thank you for referring <?php echo $patientFirstName; if( $isFirstVisit == 1 ){ echo " saw";}else{ echo " reviewed";} ?> on <?php echo $datetimeSeen?></div></td>
						<td></td>
					</tr>
				</table>
			</div>
			<div id="medicalTableDiv" style="margin:1px auto;width:1000px;">
				<table id="medicalTable" style="width:85%;margin:0px auto;">
					<tr>
						<td style="border-bottom:solid 1px black;"><div style="margin:0px 0px 5px 0px;position:relative;left:20px;"><b><u>Medical Detail:</u></b></div></td>
						<td style="width:40px;"></td>
					</tr>
					<tr>
						<td  style="border-top:solid 1px black;">Symptoms:</td>
						<td></td>
					</tr>
					<tr>
						<td style="border-bottom:solid 1px black;"><div style="min-height:35px;"><?php echo $symtoms?></div></td>
						<td></td>
					</tr>
					<tr>
						<td style="border-top:solid 1px black;">Signs:</td>
						<td></td>
					</tr>
					<tr>
						<!-- <td style="border-bottom:solid 1px black;"><div style="min-height:35px;"><?php echo $signs?></div></td> -->
						<td style="border-bottom:solid 1px black;"><?php echo $signs?></td>
						<td></td>
					</tr>
					<tr>
						<td style="border-top:solid 1px black;">Diagnosis:</td>
						<td></td>
					</tr>
					<tr>
						<td style="border-bottom:solid 1px black;"><div style="min-height:35px;"><?php echo $diagnosis?></div></td>
						<td></td>
					</tr>
					<tr>
						<td style="border-top:solid 1px black;">Treatment:</td>
						<td></td>
					</tr>
					<tr>
						<td style="border-bottom:solid 1px black;"><div style="min-height:35px;"><?php echo $treatment?></div></td>
						<td></td>
					</tr>
					<tr>
						<td style="border-top:solid 1px black;">Comments:</td>
						<td></td>
					</tr>
					<tr>
						<td style="border-bottom:solid 1px black;"><div style="min-height:35px;"><?php echo $comments?></div></td>
						<td></td>
					</tr>
				</table>
			</div>

			<div id="outLetter">
				<div id="operate" style="text-align:center;">
						<input type="button" value="print" onclick="printReport()"/>
						<input type="button" value="cancel" onclick="previousPage();"/>

				</div>
			</div>
		
		</div>
		<?php include_once 'footer.php';?>
		<iframe id="hidden_frame" name="hidden_frame" style="display:none"></iframe>
		</div> 
</body>
</html>
